<?php 
include_once('includes.php'); 	


if(isset($_GET["id"]) && $_GET["id"]>0 )
{
	$id = (int) $_GET["id"];
	$sql = "select * from competition where id=".addslashes($id);
	$competition=db_fetch_one($sql);
	
	if(isset($_GET["task"]) && $_GET["task"] == "delete" )
	{
		db_delete("competition",$id );
		Header("Location: /admin/match");
		exit;
	}
	
		
}

if($_SERVER["REQUEST_METHOD"]=="POST")
{
	$data["id"] = $_POST["id"];
	$data["name"] = $_POST["name"];
	$data["description"] = $_POST["description"];
	$data["logo"] = $_POST["logo"];
	$data["classicon"] = $_POST["classicon"];
	
	if($data["id"] >0 )
		db_update("competition",$data["id"],$data);
	else
		$competition_id=db_insert("competition",$data);		
	
	Header("Location: /admin/competition");
	exit;
}
	
?>
<?php include_once('includes/header.php'); 	 ?>
<span class="title">Create New Competition</span>


<form name="submitform" method="post" action="">
	<input type="hidden" name="id" value="<?php echo $competition->id;?>"/>
	<p>
		<label>Name</label>
		<input type="text" name="name" value="<?php echo $competition->name;?>" style="width:400px"/>
	</p>
	<p>
		<label>Description</label>
		<textarea name="description" style="width:400px; height:100px"><?php echo $competition->description;?></textarea>
	</p>
	<p>
		<label>Class Icon</label>
		<input type="text" name="classicon" value="<?php echo $competition->classicon;?>" style="width:400px"/>
	</p>
	<p>
		<label>Logo</label>
		<input type="text" name="logo" value="<?php echo $competition->logo;?>" style="width:400px"/>
	</p>
	
	<div class="button"> <input type="submit" value="Save"/>   <input type="button" value="Cancel" onclick="history.go(-1);"/>     </div>
</form>

<?php include_once('includes/footer.php'); 	 ?>